package com.zhi.mbtibot.controller;

import com.zhi.mbtibot.common.Result;
import com.zhi.mbtibot.entity.User;
import com.zhi.mbtibot.util.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能: 测试用控制器
 * 作者:YukiSu
 * 日期:2024/7/21 4:32
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    TokenUtil tokenUtil;
    @GetMapping("/login")
    public Result login(@RequestBody User user) {
        return Result.success(tokenUtil.getToken(user.getUsername(), user.getPassword()));
    }
    @PostMapping("/hello")
    public Result hello(HttpServletRequest request) {
        String token = request.getHeader("token");
        tokenUtil.parseToken(token);
        return Result.success("请求成功");
    }

}